home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / audio / modulemanipulation / mod2midi.lha / source / AmigaWIN.C next >
Encoding:
C/C++ Source or Header  |  1992-09-02  |  20.5 KB  |  964 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V1.4
  3.  *  which is (c) Copyright 1991,92 Jaba Development
  4.  */
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8.  
  9. #include <exec/types.h>
  10. #include <intuition/intuitionbase.h>
  11. #include <intuition/intuition.h>
  12. #include <intuition/classes.h>
  13. #include <intuition/classusr.h>
  14. #include <intuition/imageclass.h>
  15. #include <intuition/gadgetclass.h>
  16. #include <libraries/gadtools.h>
  17. #include <graphics/gfxbase.h>
  18.  
  19. #include <proto/exec.h>                // use amiga library stuff
  20. #include <proto/dos.h>
  21. #include <proto/graphics.h>
  22. #include <proto/intuition.h>
  23. #include <proto/gadtools.h>
  24. #include <proto/asl.h>
  25. #include <proto/utility.h>
  26. #include <proto/diskfont.h> 
  27. #include <proto/intuition.h>
  28.  
  29. #include "AmigaWIN.h"
  30. #include "rawkeys.h"
  31. #include "mod2midi_globals.h"
  32.  
  33. #include "mod2midi_rev.h"
  34.  
  35. UBYTE version_str[] = { VERSTAG };
  36.  
  37. #define    FW    7        // font width
  38. #define    FH    8        // font height
  39.  
  40. #define    Input_CNT    1
  41. #define    GD_f1        1
  42. typedef char *string;
  43.  
  44. struct Screen         *Scr = NULL;
  45. APTR                   VisualInfo = NULL;
  46. struct Window         *InputWnd = NULL;
  47. struct Gadget         *InputGList = NULL;
  48. struct Gadget         *InputGadgets[10];
  49. struct Menu           *InputMenus = NULL;
  50. UWORD                  InputLeft = 50;
  51. UWORD                  InputTop = 91;
  52. UWORD                  InputWidth = 80*FW;
  53. UWORD                  InputHeight = (25*FH)+18;
  54. UBYTE                 InputWdt[100];
  55.  
  56. struct TextAttr thinpaz8 = {
  57.     ( STRPTR )"thinpaz.font", 8, 0x00, 0x00 };
  58.  
  59. struct TextFont    *thinpazfont8;
  60.  
  61. struct NewMenu InputNewMenu[] = {
  62.     NM_TITLE, (STRPTR)"Project", NULL, 0, NULL, NULL,
  63.         NM_ITEM, (STRPTR)"Select midi file", (STRPTR)"d", 0, 0x0L, NULL,
  64.         NM_ITEM, (STRPTR)"Select source mod file", (STRPTR)"s", 0, NULL, NULL,
  65.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  66.         NM_ITEM, (STRPTR)"Convert Now", (STRPTR)"c", 0, NULL, NULL,
  67.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  68.         NM_ITEM, (STRPTR)"About", (STRPTR)"?", 0, NULL, NULL,
  69.         NM_ITEM, (STRPTR)"Quit", (STRPTR)"q", 0, NULL, NULL,
  70.     NM_TITLE, (STRPTR)"Samples", NULL, 0, NULL, NULL,
  71.         NM_ITEM, (STRPTR)"Remap Samples to MID instruments", (STRPTR)"m", 0, 0x0L, NULL,
  72.         NM_ITEM, (STRPTR)"Transposing", (STRPTR)"t", 0, NULL, NULL,
  73.         NM_ITEM, (STRPTR)"Volume Shift", (STRPTR)"v", 0, NULL, NULL,
  74.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  75.         NM_ITEM, (STRPTR)"Save Info", (STRPTR)"i", 0, NULL, NULL,
  76.     NM_TITLE, (STRPTR)"Options", NULL, 0, NULL, NULL,
  77.         NM_ITEM, (STRPTR)"Drum Channel", (STRPTR)"d", 0, 0x0L, NULL,
  78.         NM_ITEM, (STRPTR)"Tempo Type", NULL, 0, NULL, NULL,
  79. };
  80.  
  81. UWORD InputGTypes[] = {
  82.     BUTTON_KIND,
  83. };
  84.  
  85. struct NewGadget InputNGad[] = {
  86.     6, 3, 45, 12, (UBYTE *)"Quit", NULL, GD_f1, PLACETEXT_IN, NULL, NULL,
  87. };
  88.  
  89. ULONG InputGTags[] = {
  90.     (GT_Underscore), '_', (TAG_DONE),
  91. };
  92.  
  93.  
  94.  
  95.  
  96. /*
  97.  * --- Message info
  98.  */
  99. ULONG            IClass;
  100. UWORD            Qualifier, Code;
  101.  
  102. struct        Gadget    *IObject;
  103. ULONG            version;
  104.  
  105.  
  106. struct    FileRequester    *filereq;
  107.  
  108.  
  109. /*
  110.  * --- Close the libraries which are opened by me.
  111.  */
  112. void CloseLibraries( void ){
  113.     if ( filereq )
  114.         FreeAslRequest( filereq );
  115.  
  116.     if (DiskFontBase)        CloseLibrary( (struct Library *) DiskFontBase );
  117.     if (GadToolsBase)        CloseLibrary(( struct Library * )GadToolsBase );
  118.     if (IntuitionBase)    CloseLibrary(( struct Library * )IntuitionBase );
  119.     if (DosBase)            CloseLibrary(( struct Library * )DosBase );
  120.     if (GfxBase)            CloseLibrary(( struct Library * )GfxBase );
  121.     if (AslBase)            CloseLibrary(( struct Library * )AslBase );
  122. }
  123.  
  124.  
  125. /*
  126.  * --- Open lots of libraries that I need.
  127.  */
  128. long OpenLibraries( void ){
  129.     struct    TagItem    AslTags[] = { 0,0 };
  130.  
  131.     if ( !(GfxBase = (struct GfxBase *) OpenLibrary((UBYTE *) "graphics.library" , 33l ))) {
  132.         Printf("\graphics.library\n");
  133.         return FALSE;
  134.         }
  135.  
  136.     if ( !(DosBase = (struct DosBase *) OpenLibrary((UBYTE *) "dos.library", 33l ))) {
  137.         Printf("\tdos.library\n");
  138.         return FALSE;
  139.         }
  140.  
  141.     if ( !(IntuitionBase = (struct IntuitionBase *) OpenLibrary((UBYTE *) "intuition.library", 33l ))) {
  142.         Printf("\tintuition.library\n");
  143.         return FALSE;
  144.         }
  145.  
  146.     if ( !(AslBase = (struct Library *) OpenLibrary((UBYTE *) "asl.library", 37l ))) {
  147.         if ( !(AslBase = (struct Library *) OpenLibrary((UBYTE *) "asl13.library", 34l ))) {
  148.             Printf("\tasl.library\n");
  149.             return FALSE;
  150.             }
  151.         }
  152.  
  153.     if ( !(GadToolsBase = (struct Library *) OpenLibrary((UBYTE *) "gadtools.library", 36l ))) {
  154.         if ( !(GadToolsBase = (struct Library *) OpenLibrary((UBYTE *) "gadtools13.library", 34l ))) {
  155.             Printf("\tgadtools.library\n");
  156.             return FALSE;
  157.             }
  158.         }
  159.  
  160.     if ( !(DiskFontBase = (struct Library *) OpenLibrary((UBYTE *) "diskfont.library", 33l ))) {
  161.         Printf("\tdiskfont.library\n");
  162.         return FALSE;
  163.         }
  164.  
  165.     filereq = (struct FileRequester *) AllocAslRequest( ASL_FileRequest,AslTags );
  166.  
  167.     return TRUE;
  168. }
  169.  
  170.  
  171. /*
  172.  * --- Clears all message from a message port.
  173.  */
  174. void ClearMsgPort( struct MsgPort *mport )
  175. {
  176.     struct IntuiMessage  *msg;
  177.  
  178.     while ( msg = GT_GetIMsg( mport )) GT_ReplyIMsg( msg );
  179. }
  180.  
  181.  
  182.  
  183.  
  184. /*
  185.  * --- Reads a message from the window message port.
  186.  * --- Returns TRUE if a message was read and puts the
  187.  * --- message data in the globals. Return FALSE if there
  188.  * --- was no message at the port.
  189.  */
  190. long ReadIMsg( struct Window *iwnd )
  191. {
  192.     struct IntuiMessage *imsg;
  193.  
  194.     if ( imsg = GT_GetIMsg( iwnd->UserPort )) {
  195.  
  196.         IClass      =   imsg->Class;
  197.         Qualifier   =   imsg->Qualifier;
  198.         Code        =   imsg->Code;
  199.         IObject     =   imsg->IAddress;
  200.  
  201.         GT_ReplyIMsg( imsg );
  202.  
  203.         return TRUE;
  204.     }
  205.     return FALSE;
  206. }
  207.  
  208.  
  209.  
  210.  
  211. /**********************************************************************
  212.  *
  213.  *                        Draw3DOutBox
  214.  *    Description : just like normal bevelbox except inside color is selectable
  215.  *                  plus it looks MONUMENTAL!
  216.  *                                ¯¯¯¯¯¯¯¯¯¯¯
  217.  *  Returns        : NULL
  218.  *    Globals        : usual
  219.  *
  220.  */
  221. void Draw3DBox(
  222.     struct    RastPort *rp,        // window rastport to draw into
  223.     UWORD    xpos,                // X coordinate to place MEGA-BEVEL
  224.     UWORD    ypos,                // Y coordinate to place MEGA-BEVEL
  225.     UWORD    xsize,                // X size of MEGA-BEVEL
  226.     UWORD    ysize,                // X size of MEGA-BEVEL
  227.     UWORD    shine_pen,            // top-left pen
  228.     UWORD    body_pen,            // central pen
  229.     UWORD    shadow_pen            // bot-right pen
  230. ){
  231.  
  232. #define    LineDraw(x,y,x2,y2)    Move( rp, x , y); \
  233.                             Draw( rp, x2, y2 )
  234.  
  235.     xsize--;ysize--;
  236.  
  237.     SetAPen( rp, body_pen );
  238.     RectFill( rp, xpos, ypos, xpos+xsize, ypos+ysize);
  239.  
  240.     LineDraw( xpos, ypos, xpos+1, ypos+1 );
  241.     LineDraw( xpos+xsize-1, ypos+ysize-1, xpos+xsize, ypos+ysize );
  242.  
  243.     SetAPen( rp, shine_pen );
  244.     LineDraw( xpos+0, ypos+0, xpos+xsize-1, ypos );
  245.     LineDraw( xpos+0, ypos+1, xpos+xsize-2, ypos+1 );
  246.     LineDraw( xpos+0, ypos+0, xpos, ypos+ysize-1 );
  247.     LineDraw( xpos+1, ypos+0, xpos+1, ypos+ysize-2 );
  248.  
  249.     SetAPen( rp, shadow_pen );
  250.     LineDraw( xpos+1, ypos+ysize-0, xpos+xsize-1, ypos+ysize-0 );
  251.     LineDraw( xpos+2, ypos+ysize-1, xpos+xsize-2, ypos+ysize-1 );
  252.     LineDraw( xpos+xsize-0, ypos+1, xpos+xsize-0, ypos+ysize-1 );
  253.     LineDraw( xpos+xsize-1, ypos+2, xpos+xsize-1, ypos+ysize-2 );
  254.  
  255.     SetAPen( rp, 2 );
  256.     if ( shine_pen > shadow_pen ){
  257.         LineDraw( xpos+0, ypos+0, xpos+2, ypos+0 );
  258.         LineDraw( xpos+0, ypos+0, xpos+0, ypos+2 );
  259.     }
  260.     else {
  261.         LineDraw( xpos+xsize, ypos+ysize, xpos+xsize-2, ypos+ysize );
  262.         LineDraw( xpos+xsize, ypos+ysize, xpos+xsize-0, ypos+ysize-2 );
  263.     }
  264. }
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272. int OpenInputWindow( void )
  273. {
  274.     struct NewGadget    ng;
  275.     struct Gadget    *g;
  276.     UWORD        lc, tc;
  277.     UWORD        offx, offy;
  278.  
  279.     OpenLibraries();
  280.     version=GfxBase->LibNode.lib_Version;
  281.     Scr = IntuitionBase->ActiveScreen;
  282.     if ( ! (thinpazfont8  = OpenDiskFont( &thinpaz8 )) ) {
  283.             ;
  284.         }
  285.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  286.         return( 1L );
  287.     offx = Scr->WBorLeft; offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  288.  
  289.  
  290.  
  291.     if ( ! ( g = CreateContext( &InputGList )))
  292.         return( 1L );
  293.  
  294.     for( lc = 0, tc = 0; lc < Input_CNT; lc++ ) {
  295.  
  296.         CopyMem((char * )&InputNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  297.  
  298.         ng.ng_VisualInfo = VisualInfo;
  299.         ng.ng_TextAttr   = &thinpaz8;
  300.         ng.ng_LeftEdge  += offx;
  301.         ng.ng_TopEdge   += offy;
  302.  
  303.         InputGadgets[ lc ] = g = CreateGadgetA((ULONG)InputGTypes[ lc ], g, &ng, ( struct TagItem * )&InputGTags[ tc ] );
  304.  
  305.         while( InputGTags[ tc ] ) tc += 2;
  306.         tc++;
  307.  
  308.         if ( NOT g )
  309.             return( 2L );
  310.     }
  311.  
  312.  
  313.     if ( ! ( InputMenus = CreateMenus( InputNewMenu,
  314.                     GTMN_FrontPen,        2L,
  315.                     TAG_DONE )))
  316.         return( 3L );
  317.  
  318.     LayoutMenus( InputMenus, VisualInfo,
  319.             //        GTMN_TextAttr,         &helvetica18,
  320.                     GTMN_NewLookMenus,    TRUE,
  321.                     TAG_DONE );
  322.  
  323.     if ( ! ( InputWnd = OpenWindowTags( NULL,
  324.                 WA_Left,        InputLeft,
  325.                 WA_Top,            InputTop,
  326.                 WA_Width,        InputWidth,
  327.                 WA_Height,        InputHeight + offy,
  328.                 WA_IDCMP,        IDCMP_MOUSEBUTTONS|BUTTONIDCMP|INTEGERIDCMP|
  329.                                 IDCMP_CHANGEWINDOW|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|
  330.                                 IDCMP_ACTIVEWINDOW|IDCMP_MENUPICK|IDCMP_VANILLAKEY|IDCMP_RAWKEY,
  331.                 WA_Flags,        WFLG_NEWLOOKMENUS|WFLG_ACTIVATE|WFLG_DRAGBAR|WFLG_DEPTHGADGET|
  332.                                 WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_GIMMEZEROZERO,
  333.             //    WA_Gadgets,        InputGList,
  334.                 WA_Title,        InputWdt,
  335.                 WA_PubScreen,    NULL,
  336.                 WA_MinWidth,    InputWidth,
  337.                 WA_MinHeight,    InputHeight + offy,
  338.                 WA_MaxWidth,    InputWidth + 140,
  339.                 WA_MaxHeight,    InputHeight + offy + 500,
  340.                 TAG_DONE )))
  341.     return( 4L );
  342.  
  343.     SetMenuStrip( InputWnd, InputMenus );
  344.  
  345.     GT_RefreshWindow( InputWnd, NULL );
  346.  
  347.     SetFont( InputWnd->RPort, thinpazfont8 );
  348.  
  349.     return( 0L );
  350. }
  351.  
  352. void CloseInputWindow( void )
  353. {
  354.     InputLeft = InputWnd->LeftEdge;
  355.     InputTop = InputWnd->TopEdge;
  356.  
  357.     if ( InputMenus      ) {
  358.         ClearMenuStrip( InputWnd );
  359.         FreeMenus( InputMenus );
  360.         InputMenus = NULL;    }
  361.  
  362.     if ( InputWnd        ) {
  363.         CloseWindow( InputWnd );
  364.         InputWnd = NULL;
  365.     }
  366.  
  367.     if ( InputGList      ) {
  368.         FreeGadgets( InputGList );
  369.         InputGList = NULL;
  370.     }
  371. }
  372.  
  373.  
  374.  
  375.  
  376.  
  377. /**********************************************************************
  378.  *
  379.  *                        InputMenus()
  380.  *    Description : Handles all menu events
  381.  *  Returns        : BOOL
  382.  *    Globals        :
  383.  *
  384.  */
  385. LONG HandleInputMenus( void ){
  386.     struct    MenuItem        *Next;
  387.     LONG    ret=-1;
  388.     UWORD    menu, item, sub;
  389.  
  390.     while( Code != MENUNULL ) {
  391.         Next = ItemAddress(  InputMenus, Code );
  392.         menu = MENUNUM( Code );
  393.         item = ITEMNUM( Code );
  394.         sub  = SUBNUM( Code );
  395.         switch ( menu ) {
  396.             case    0:
  397.                 switch ( item ) {
  398.                     case    0:    ret = 0; break;
  399.                     case    1:    ret = 1; break;
  400.                     case    3:    ret = 2; break;
  401.                     case    5:    ret = 5; break;
  402.                     case    6:    ret = 99; break;
  403.                 }
  404.                 break;
  405.             case    1:
  406.                 switch ( item ) {
  407.                     case    0:    ret = 3; break;        // remap
  408.                     case    1:    ret = 6; break;        // transpose
  409.                     case    2:    ret = 9; break;        // volume
  410.                     case    4:    ret = 4; break;        // save info
  411.                 }
  412.                 break;
  413.             case    2:
  414.                 switch ( item ) {
  415.                     case    0:    ret = 7; break;        // drum ch
  416.                     case    1:    ret = 8; break;        // tempo
  417.                     case    2:    ret = 8; break;        //  "
  418.                 }
  419.                 break;
  420.         }
  421.         Code = Next->NextSelect;
  422.     }
  423.     return ret;
  424. }
  425.  
  426.  
  427.     WORD    rawkey=0;
  428.     WORD    normkey=0;
  429.  
  430. int GetIntuiEvent( void ){
  431.     int ret=-1;
  432.  
  433. //printf("waitport\n");
  434.     WaitPort( InputWnd->UserPort );
  435. //    while ( ReadIMsg( InputWnd )) {
  436.         ReadIMsg( InputWnd ); {
  437. //printf("decode msg\n");
  438.         ret=-1;
  439.         rawkey=NULL; normkey = NULL;
  440.         switch ( IClass ) {
  441.             case    IDCMP_CLOSEWINDOW:            // Key short cuts
  442.                 ret = 99;
  443.                 break;
  444.  
  445.             case    IDCMP_MOUSEBUTTONS:
  446.                 switch ( Code ){
  447.                     case SELECTUP:
  448.                         break;
  449.                     case SELECTDOWN:
  450.                         break;
  451.                 }
  452.                 break;
  453.  
  454.             case    IDCMP_GADGETUP:
  455.                 switch ( IObject->GadgetID ) {
  456.                     case    GD_f1:
  457.                         ret = 99;
  458.                         break;
  459.                 }
  460.                 break;
  461.  
  462.             case    IDCMP_VANILLAKEY:            // Key short cuts
  463.                 normkey = Code;
  464.                 break;
  465.  
  466.             case    IDCMP_RAWKEY:
  467.                 switch( Code ){
  468.                     case KEY_UP        :
  469.                     case KEY_DOWN    :
  470.                     case KEY_LEFT    :
  471.                     case KEY_RIGHT    : rawkey = Code;    break;
  472.                     default            : rawkey = NULL;    break;
  473.                 }
  474.                 break;
  475.  
  476.             case    IDCMP_MENUPICK:
  477.                 ret = HandleInputMenus();
  478.                 break;
  479.  
  480.             case    IDCMP_CHANGEWINDOW:
  481.                 break;
  482.  
  483.             case    IDCMP_ACTIVEWINDOW:
  484.                 ClearMsgPort( InputWnd->UserPort );
  485.                 break;
  486.  
  487.             case    IDCMP_REFRESHWINDOW:
  488.                 GT_BeginRefresh( InputWnd );
  489.                 GT_EndRefresh( InputWnd, TRUE);
  490.                 break;
  491.         }
  492.     }
  493. //printf("ret=%d   normkey=%d  rawkey=%d\n",ret,normkey,rawkey);
  494.     return ret;
  495. }
  496.  
  497.  
  498.  
  499.  
  500. /**********************************************************************
  501.  *
  502.  *                        AslFileRequest
  503.  *
  504.  *    Description : Put up the ASL FileRequester
  505.  *    Returns        : UBYTE pointer to filename ascii (NULL terminated)
  506.  *    Globals        :
  507.  *
  508.  */
  509. UBYTE *AslFileRequest(
  510.     UBYTE type,                // 'l'=load / 's'=save
  511.     UBYTE *title,            // title of requester window
  512.     UBYTE *drawer,            // the drawer to open into
  513.     UBYTE *pattern            // the pattern to use
  514. ){
  515. static
  516.     UBYTE    FileName[180];
  517.     UBYTE    *char1, *ret;
  518.     UWORD    flag1, flag2, len, x, y;
  519.  
  520.     ret = 0;
  521.  
  522.     if( !filereq ) return ret;
  523.  
  524.     x = 10;                // get current mouse coords
  525.     y = 10;
  526.  
  527.     switch( type ) {
  528.         case    's':
  529.             char1 = "Save";
  530.             flag1 = FILF_SAVE | FILF_PATGAD;
  531.             flag2 = TRUE;
  532.             break;
  533.         case    'l':
  534.             char1 = "Open";
  535.             flag1 = FILF_PATGAD;
  536.             flag2 = FALSE;
  537.             break;
  538.         }
  539.  
  540.     if ( AslRequestTags( filereq,
  541.                         ASL_OKText,             char1,
  542.                         ASL_Hail,                 flag1,
  543.                     //    ASLFR_Screen,             CurrentScr,
  544.                         ASLFR_TitleText,         title,
  545.                         ASLFR_InitialLeftEdge,    x,
  546.                         ASLFR_InitialTopEdge,    y,
  547.                         ASLFR_InitialWidth,        300,
  548.                         ASLFR_InitialHeight,    284,
  549.                         ASLFR_InitialDrawer,    drawer,
  550.                         ASLFR_DoSaveMode,        flag2,
  551.                         ASLFR_DoPatterns,        TRUE,
  552.                         ASLFR_InitialPattern,    pattern,
  553.                     //    ASLFR_TextAttr,            &helvetica13,        //    &mflex10,
  554.                         TAG_DONE ) ) {
  555.         strcpy( FileName, filereq->rf_Dir );
  556.         len = strlen( FileName );
  557.         if ( len-- )
  558.             if ( FileName[ len ] != '/' && FileName[ len ] != ':' )
  559.                 strcat( FileName, "/" );
  560.         strcat( FileName, filereq->rf_File );
  561.         ret = FileName;
  562.     }
  563.  
  564.     return( ret );
  565. }
  566.  
  567.  
  568.  
  569. //--------------------------------------------------------------------------
  570.  
  571. UBYTE    str[100];
  572.  
  573. void cprintf( UBYTE *a, int b, UBYTE *c ){
  574.     int len=strlen(c);
  575.  
  576.     if( *(c+len-1) == 13 ) *(c+len-1)=NULL;
  577.     sprintf(str,a,b,c);
  578.     Text( InputWnd->RPort, str, strlen(str) );
  579. }
  580.  
  581. void cputs( UBYTE *a ){
  582.     Text( InputWnd->RPort, a, strlen(a) );
  583. }
  584.  
  585. void cputchar( UBYTE *a, UBYTE c ){
  586.     sprintf(str,a,c);
  587.     Text( InputWnd->RPort, str, strlen(str) );
  588. }
  589.  
  590.  
  591. //--------------------------------------------------------------------------
  592.  
  593.  
  594. void MainWindow(string title, int num, ...)
  595. /* Post: Screen is set up with a nice title and num menus */
  596. {
  597.     va_list args;
  598.  
  599.     strcpy( InputWdt, title );
  600.  
  601.     OpenInputWindow();
  602. }
  603.  
  604.  
  605. void EndWindows( void ){
  606.     if ( thinpazfont8 )
  607.         CloseFont( thinpazfont8 );
  608.     CloseInputWindow();
  609.     CloseLibraries();
  610. }
  611.  
  612.  
  613.     WORD    curr_x=0,curr_y=0,
  614.             left_x=0,top_y=0,
  615.             right_x=0,bottom_y=0,
  616.             pos_x=0,pos_y=0;
  617.  
  618. void gotoxy( WORD x, WORD y ){
  619.     pos_x = x; pos_y=y;
  620.     curr_x=(x+left_x)*FW;    curr_y=(y+top_y)*FH;
  621.     Move( InputWnd->RPort, curr_x, curr_y );
  622. }
  623. void textcolor( WORD n ){
  624.     SetAPen( InputWnd->RPort, n );
  625. }
  626. void textbackground( WORD n ){
  627.     SetBPen( InputWnd->RPort, n );
  628. }
  629.  
  630. void window( int x, int y, int x2, int y2 ){
  631.     left_x  =x;        top_y   =y;
  632.     right_x =x2;    bottom_y=y2;
  633. //printf("window:x=%d y=%d x2=%d y2=%d\n",x, y, x2, y2);
  634. }    
  635.  
  636. void renderwindow( int x, int y, int x2, int y2 ){
  637.     Draw3DBox( InputWnd->RPort, (x*FW)-12, (y*FH)-6, (x2*FW)+12, (y2*FH)+16, 2,3,1 );
  638. //printf("rwindow:x=%d y=%d x2=%d y2=%d\n",x, y, x2, y2);
  639. }
  640.  
  641.  
  642. void PrintBar(string s, int w, int y)
  643. /* Post: String s (width w) is highlighted in the text window on line y */
  644. {
  645.     gotoxy(1, y+1);
  646.     textcolor(1);
  647.     textbackground(2);
  648.     cprintf(" %-*s ", w, s);
  649. }
  650.  
  651. void ClearBar(string s, int w, int y)
  652. /* Post: String s (width w) is normalized in the text window on line y */
  653. {
  654.     gotoxy(1, y+1);
  655.     textcolor(2);
  656.     textbackground(3);
  657.     cprintf(" %-*s ", w, s);
  658. }
  659.  
  660. void Beep( void ){
  661.     DisplayBeep( NULL );
  662. }
  663.  
  664. int Choice( void ){
  665.     int ret=-1;
  666.  
  667.     ret = GetIntuiEvent();
  668.  
  669.     return ret;
  670. }
  671.  
  672.  
  673. void ScrollWindowUp( void ){
  674.     ClipBlit( InputWnd->RPort, left_x*FW, ((top_y+1)*FH)+2,
  675.               InputWnd->RPort, left_x*FW, ((top_y)*FH)+2,
  676.              (right_x-left_x)*FW,
  677.              ((bottom_y-top_y-1)*FH)+2, 0xc0 );
  678. }
  679.  
  680. void ScrollWindowDown( void ){
  681.     ClipBlit( InputWnd->RPort, left_x*FW, (top_y*FH)+2,
  682.               InputWnd->RPort, left_x*FW, ((top_y+1)*FH)+2,
  683.              (right_x-left_x)*FW,
  684.              ((bottom_y-top_y-1)*FH), 0xc0 );
  685. }
  686.  
  687.  
  688.  
  689.  
  690. void insline( void ){
  691.     ;
  692. }
  693.  
  694. void clreol( int x ){
  695.     int lp;
  696.  
  697.     cprintf(" %-*s ", right_x-(x+left_x), " ");
  698. }
  699.  
  700.  
  701. #define getch GetCursorKeys
  702. WORD GetCursorKeys( void ){
  703.     GetIntuiEvent();
  704.     if( rawkey ) {
  705.         if( rawkey == KEY_UP ) return -72;
  706.         if( rawkey == KEY_DOWN ) return -80;
  707.         if( rawkey == KEY_LEFT ) return -75;
  708.         if( rawkey == KEY_RIGHT ) return -77;
  709.     }
  710.     else
  711.         return normkey;
  712. }
  713.  
  714.  
  715. void ClearWin( void ){
  716.     textcolor(0);
  717.     RectFill( InputWnd->RPort, 0, 0, 80*FW,(26*FH)+1);
  718.     window(1, 1, 80, 25);
  719. }
  720.  
  721.  
  722. int ScrollChoice( char *title, char **sp, int w)
  723. /*
  724.  * Returns: The offset of the string from s which is chosen, -1 on none
  725.  *    s points to the start of a list of strings, max length w, NULL term.
  726.  */
  727. {
  728.     string s, t, *srt, *end;
  729.     int l, p, cur, ch, x = -1;
  730.  
  731.     if (strlen(title) > w)
  732.         w = strlen(title);
  733.  
  734.     textcolor(1);
  735.     textbackground(0);
  736.     gotoxy(1, 25);
  737.     cputs("Use cursor keys and <RETURN> to make a selection (ESC=back one level).");
  738.  
  739.     for (end = sp, l = 0; *end!=NULL && l<20; l++);
  740.  
  741.     renderwindow(6, 1, w, l+1);
  742.  
  743.     textcolor(2);
  744.     textbackground(3);
  745.     gotoxy(3 + (w - strlen(title))/2, 1);
  746.     cprintf("-- %-*s --", 14, title );
  747.  
  748.     srt = end = sp;
  749.     for (end = sp, l = 0; *end!=NULL && l<20; l++) {
  750.         gotoxy(6, l+2);
  751.         cprintf(" %-*s", w, *(end++) );
  752.     }
  753.     end--;
  754.  
  755.     window(6, 2, 8+w, l+2);
  756.  
  757.     PrintBar(*srt, w, p = 0);
  758.     cur = 0;
  759.     x = -1;
  760.     do {
  761.         ch = GetCursorKeys();
  762.         if(ch<0) {
  763.             if (ch==-72)
  764.                 if (!cur)
  765.                     Beep();
  766.                 else if (p) {
  767.                     ClearBar(*(srt+p), w, p);
  768.                     p--;
  769.                     PrintBar(*(srt+p), w, p);
  770.                     cur--;
  771.                 } else {
  772.                     ClearBar(*(srt--), w, 0);
  773.                     gotoxy(1, 1);
  774.                     ScrollWindowDown();
  775.                     gotoxy(w+3, 1);
  776.                     PrintBar(*srt, w, 0);
  777.                     end--;
  778.                     cur--;
  779.                 }
  780.             else if (ch==-80)
  781.                 if (p==l-1 && *(end+1)==NULL)
  782.                     Beep();
  783.                 else if (p < l-1) {
  784.                     ClearBar(*(srt+p), w, p);
  785.                     p++;
  786.                     cur++;
  787.                     PrintBar(*(srt+p), w, p);
  788.                 } else {
  789.                     ClearBar(*end, w, p);
  790.                     end++;
  791.                     ScrollWindowUp();
  792.                     gotoxy(w+3, l);
  793.                     cur++;
  794.                     PrintBar(*end, w, p);
  795.                     srt++;
  796.                 }
  797.         } else
  798.         if (ch==13)
  799.             x = cur;
  800.     } while (x < 0 && ch != 27);
  801.     ClearWin();
  802.     return x;
  803. }
  804.  
  805.  
  806.  
  807. /* returns the ysize of the box drawn */
  808. int PrintBox(string *sp, int *x1, int *y1, int *w1) {
  809.     int w, x, i, j, ys=0;
  810.     string s, t, *c;
  811.  
  812.     if (*sp==NULL)
  813.         return;
  814.     c = sp;
  815.     for (w = strlen(*(c++)), i = 1; *c!=NULL; c++, i++)
  816.         if (w < (x = strlen(*c)))
  817.             w = x;
  818.     *w1 = w + 2;
  819.     *x1 = 1 + (x = (76 - w)/2);
  820.     i = 1 + (21 - i)/2;
  821.     *y1 = i-1;
  822.  
  823.     for (c = sp; *c!=NULL; c++) ys++;
  824.  
  825.     window( *x1, *y1, *w1, ys );
  826.     renderwindow( *x1, *y1, *w1, ys );
  827.  
  828.     textcolor(2);
  829.     textbackground(3);
  830.  
  831.     x=1;i=1;
  832.     for (c = sp; *c!=NULL; c++) {
  833.         gotoxy(x, i++);
  834.         w = strlen(*c);
  835.         cprintf(" %-*s ", w, *c);
  836.     }
  837.     return ys;
  838. }
  839.  
  840.  
  841. void DrawBox( char **sp)
  842. /* Post: The NULL-terminated array of strings pointed to by sp is printed */
  843. {
  844.     int i,i2,i3;
  845.     PrintBox(sp, &i, &i2, &i3);
  846. }
  847.  
  848.  
  849. char InfoBox( char **sp)
  850. /*
  851.  * Returns: The key pressed after the NULL-terminated array of strings
  852.  *    pointed to by sp is printed.
  853.  */
  854. {
  855.     int k;
  856.  
  857.     ClearWin();
  858.     DrawBox(sp);
  859.     window(1, 1, 80, 25);
  860.     textcolor(1);
  861.     textbackground(0);
  862.     gotoxy(1, 25);
  863.     Text( InputWnd->RPort, "Please press a key.", 18 );
  864.     k = GetCursorKeys();
  865.     ClearWin();
  866.     gotoxy(1, 25);
  867.     Text( InputWnd->RPort, "OK.                ", 18 );
  868.     return (char)k;
  869. }
  870.  
  871.  
  872.  
  873. string FileSelect( char **sp, string def)
  874. /* Pre: def != NULL */
  875. /*
  876.  * Returns: The string entered (or def if none entered), after printing
  877.  *    box filled with NULL-terminated strings sp.
  878.  */
  879. {
  880.     string s;
  881.  
  882.     s = AslFileRequest( 'l', *sp, "" , "#?" );
  883.  
  884.     return s;
  885. }
  886.  
  887.  
  888.  
  889.  
  890. string DialogBox( char **sp, string def)
  891. /* Pre: def != NULL */
  892. /*
  893.  * Returns: The string entered (or def if none entered), after printing
  894.  *    box filled with NULL-terminated strings sp.
  895.  */
  896. {
  897.     int x, y, w, ch, i=0, ys;
  898.     string s;
  899.  
  900.     ys=PrintBox(sp, &x, &y, &w);
  901.     s = (string) malloc(w+1);
  902.     s[w] = 0;
  903.     strncpy(s, def, w);
  904.     textcolor(2);
  905.     textbackground(3);
  906.     gotoxy(1, 25);
  907.     cputs("Enter text, and when you are finished, press <RETURN>.");
  908.     textcolor(1);
  909.     textbackground(0);
  910.     window(x, y, x+w-1, y);
  911.     gotoxy(1, ys-1);
  912.     cprintf("%-*s", w, s);
  913.     gotoxy(1, ys-1);
  914.     x = strlen(s);
  915.     do {
  916.         if (!(ch = getch()))
  917.             ch = -getch();
  918.         if (ch==8 || ch==127)
  919.             if (!i)
  920.                 Beep();
  921.             else {
  922.                 x = --i;
  923.                 gotoxy(1+x, ys-1);
  924.                 cputchar(" ",0);
  925.                 gotoxy(1+x, ys-1);
  926.         //        clreol( x );
  927.             }
  928.  
  929. /*        else if (ch==-75)            // left
  930.             if (!i)
  931.                 Beep();
  932.             else {
  933.                 cputchar("\b",0);
  934.                 i--;
  935.             }
  936.         else if (ch==-77)            // right
  937.             if (i==x)
  938.                 Beep();
  939.             else {
  940.                 cputchar("%c", s[i]);
  941.                 i++;
  942.             }
  943. */
  944.         else if (ch!=13 && ch!=27)
  945.             if (i==w-1)
  946.                 Beep();
  947.             else {
  948.                 cputchar("%c", ch);
  949.                 if (i==x)
  950.                     x++;
  951.                 s[i++] = ch;
  952.             }
  953.     } while (ch!=13 && ch!=27);
  954.     s[x] = 0;
  955.     if (ch==27) {
  956.         free(s);
  957.         strcpy(s = (string) malloc(strlen(def)+1), def);
  958.     }
  959.     ClearWin();
  960.     return s;
  961.  
  962. }
  963.  
  964.